// wigets/business/market/index.js
const componentBehavior = require('../../../js/common/ComponentBehavior');
const { router } = require('../../../js/router');

Component({
  behaviors: [componentBehavior],
  lifetimes:{
    attached() {
      // this.caculateMarket();
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {
    marketSource:Object
  },
  
  observers: {
    marketSource (marketSource) {
      let mustBuyGoods = marketSource.MustBuyGoods || []
      this.setData({
        mustBuyGoods
      })
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isLong:false,  //是否超长
    isCut:false,   //是否收起
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 计算促销高度
     */
    caculateMarket(){
      var that = this;
      var query = wx.createSelectorQuery().in(this);
      query.select('.market-scroll-cont').fields({
        size: true
      },function(res){
        console.log(res.height,'=====');
        if(res.height > 69){
          that.setData({
            isLong:true,
            isCut:true
          })
        }else{
          that.setData({
            isLong:false,
            isCut:false
          })
        }
        
      }).exec();
    },
    /**
     * 切换展开收起
     */
    switchMore(){
      this.setData({
        isCut:!this.data.isCut
      })
    },
    /**
     * 点击查看必买商品
     */
    toMustBuy() {
      let mustBuyGoods = this.data.mustBuyGoods || []
      let goodsIds = mustBuyGoods.map(item => {
        return item.GoodsId || ''
      })
      goodsIds = goodsIds.join(',')
      router.navigate({
        path: "mustBuyProductList",
        params: {
          goodsIds
        }
      })
    }
  }
})
